# delimit ;
clear ;
cd "replication" ;
set more off ; 

* *************************************************************************** ;
* load data 
* *************************************************************************** ;

use "./data/endline.dta", clear ; 

****************************************************************************** ;
* generate randomization strata and wave-class variable
****************************************************************************** ;

egen strata = group(wave neighborhood female mfi) ;
egen waveclass = group(wave class) ;

****************************************************************************** ;
* label variables for the LaTeX tables
****************************************************************************** ;

label var healthonly "HEE" ;
label var healthandpay "HEEC" ;

global module1_components "wash_defecation wash_eating wash_cooking" ; 
global module23_components "pregnancy_dai_certificate pregnancy_breastmilk diar_know" ;
global module4_components "aids_heard aids_blood aids_sex aids_touch aids_needle aids_pregnant aids_pregnant_baby aids_curable condom_hiv condom_std condom_pregnancy condom_disease" ;
global module5_components "nightblindness_heard nightblindness_nutrition nightblindness_curable" ;

* module 1 ; 
label var wash_defecation "\shortstack[l]{Knows\\should\\wash\\hands\\after\\defecation}" ;
label var wash_eating "\shortstack[l]{Knows\\should\\wash\\hands\\before\\eating}" ;
label var wash_cooking "\shortstack[l]{Knows\\should\\wash\\hands\\before\\cooking}";  

* module 2-3 ;
label var pregnancy_dai_certificate "\shortstack[l]{Knows\\trained\\midwife\\has a\\certificate\\or ID}" ;
label var pregnancy_breastmilk "\shortstack[l]{Knows\\baby\\should be\\fed\\breastmilk\\after\\birth}" ;
label var diar_know "\shortstack[l]{Knows\\to give\\child w/\\diarrhea\\more\\liquids\\than\\normal}" ;

* module 4 ; 
label var aids_heard "\shortstack[l]{Has\\heard of\\AIDS}" ;
label var aids_blood "\shortstack[l]{Knows\\can get\\AIDS\\through\\blood\\trans-\\fusion}" ;
label var aids_sex "\shortstack[l]{Knows\\can get\\AIDS\\due to\\unpro-\\tected\\sex}" ;
label var aids_touch "\shortstack[l]{Knows\\can't get\\AIDS\\by\\touching\\infected\\person}" ;
label var aids_needle "\shortstack[l]{Knows\\can get\\AIDS\\through\\infected\\needle}" ;
label var aids_pregnant "\shortstack[l]{Knows\\AIDS\\can pass\\from\\pregnant\\mother\\to\\child}" ;
label var aids_pregnant_baby "\shortstack[l]{Knows\\HIV+\\mother\\won't\\always\\give birth\\to HIV+\\baby}" ;
label var aids_curable "\shortstack[l]{Knows\\AIDS\\is not\\curable}" ;
label var condom_hiv "\shortstack[l]{Knows\\con-\\doms\\prevent\\HIV}" ;
label var condom_std "\shortstack[l]{Knows\\con-\\doms\\prevent\\STDs}" ;
label var condom_pregnancy "\shortstack[l]{Knows\\con-\\doms\\prevent\\unwan-\\ted\\preg-\\nancy}" ;
label var condom_disease "\shortstack[l]{Knows\\con-\\doms\\don't\\cause\\disease}" ;

* module 5 ;
label var nightblindness_heard "\shortstack[l]{Has \\heard of\\night\\blindness}" ;
label var nightblindness_nutrition "\shortstack[l]{Knows\\can get\\night\\blindness\\from\\ poor\\nutrition}" ;
label var nightblindness_curable "\shortstack[l]{Knows\\night\\blindness\\is curable}" ;

* *******************************************************************************
* regressions, by topic/module: cleanliness, midwives/maternal/childhealth, nightblindness ; 
* ******************************************************************************* ;

est drop _all ;

foreach var in $module1_components $module23_components $module5_components { ;
	
	areg `var' healthonly healthandpay, a(strata) robust ;
	qui est sto `var'; 
	
	test healthonly = healthandpay ; 
	estadd local titlerow = "" ; 
	estadd scalar fstat = r(F): `var' ; 
	estadd scalar pval = r(p): `var' ; 

	summarize `var' if control == 1 & e(sample) == 1;
	estadd scalar cmean = r(mean): `var' ; 
	estadd scalar csd = r(sd): `var' ;
	
} ;

esttab * using "./output/appendix-table-endline-knowledge-by-question-modules-1-2-3-5.tex",
	replace
	drop(_cons) 
	cells(b(label() star fmt(%9.3f %9.3f)) se(par)) 
	star(* 0.10 ** 0.05 *** 0.01) 
	stats(titlerow fstat pval cmean csd N, fmt(%9s %9.3f %9.3f %9.3f %9.3f %9.0f) labels("\(F\)-test, HEE = HEEC" "$\qquad$ \(F\)-statistic" "$\qquad$ \(p\)-value" "Control Mean" "Control SD" "N"))
	prehead(\begin{table}\centering \normalsize `"\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}"'
		\captionsetup{justification=centering} 
		\caption{Effects on Longer-Term Health Knowledge, Individual Questions}
		\label{table-endline-knowledge-by-question-modules-1-2-3-5}
		\begin{tabular*}{\hsize}{p{3.8cm}p{1.5cm}p{1.5cm}p{1.5cm}p{1.5cm}p{1.5cm}p{1.5cm}p{1.5cm}p{1.5cm}p{1.5cm}}
		\toprule)
	legend label  booktabs  collabels( , none)
	mgroups(
	"Cleanliness and Hygiene" 
	"Midwives, Maternal \& Child Health" 
	"Nightblindness"
	, pattern(1 0 0 1 0 0 1 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))
	postfoot(`"\bottomrule"'  \end{tabular*} \captionsetup{justification=justified, width=\hsize} 
		\caption*{\footnotesize \textit{Notes:} 
		Outcomes are from an endline survey conducted 10 months after the final film screening.
		The dependent variables are all dummies for 
		whether the respondent answered the given knowledge question correctly. 
		\textit{HEE} is a dummy for assignment to only health entertainment-education. 
		\textit{HEEC} is a dummy for assignment to health entertainment-education with cash incentives for test performance. 
		Robust standard errors.
		All regressions include dummies for randomization strata, where strata are defined by gender, neighborhood, and microfinance client status.
		***\$\,p < 0.01$, **\$\,p < 0.05$, *\$\,p<0.10$.
		}
		\end{table}) ;

* *******************************************************************************
* regressions, by topic/module: condom, aids, syphilis
* ******************************************************************************* ;

est drop _all ;

foreach var in $module4_components { ;
	
	areg `var' healthonly healthandpay, a(strata) robust ;
	qui est sto `var'; 
	
	test healthonly = healthandpay ; 
	estadd local titlerow = "" ; 
	estadd scalar fstat = r(F): `var' ; 
	estadd scalar pval = r(p): `var' ; 

	summarize `var' if control == 1 & e(sample) == 1;
	estadd scalar cmean = r(mean): `var' ; 
	estadd scalar csd = r(sd): `var' ;

} ;

esttab * using "./output/appendix-table-endline-knowledge-by-question-module-4.tex",
	replace
	drop(_cons) 
	cells(b(label() star fmt(%9.3f %9.3f)) se(par)) 
	star(* 0.10 ** 0.05 *** 0.01) 
	stats(titlerow fstat pval cmean csd N, fmt(%9s %9.3f %9.3f %9.3f %9.3f %9.0f) labels("\(F\)-test, HEE = HEEC" "$\qquad$ \(F\)-statistic" "$\qquad$ \(p\)-value" "Control Mean" "Control SD" "N"))
	prehead(\begin{table}\centering \footnotesize `"\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}"'
		\captionsetup{justification=centering} 
		\caption{Effects on Longer-Term Health Knowledge, Individual Questions (continued)}
		\label{table-endline-knowledge-by-question-modules-4}
		\begin{tabular*}{\hsize}{p{3.2cm}p{1.3cm}p{1.3cm}p{1.3cm}p{1.3cm}p{1.3cm}p{1.3cm}p{.3cm}p{1.3cm}p{1.3cm}p{1.3cm}p{1.3cm}p{1.3cm}}
		\toprule)
	legend label  booktabs  collabels( , none)
	mgroups(
	"Condoms, AIDS, Syphilis"
	, pattern(1 0 0 0 0 0 0 0 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))
	postfoot(`"\bottomrule"'  \end{tabular*} \captionsetup{justification=justified, width=\hsize} 
		\caption*{\scriptsize \textit{Notes:} 
		Outcomes are from an endline survey conducted 10 months after the final film screening.
		The dependent variables are all dummies for 
		whether the respondent answered the given knowledge question correctly. 
		\textit{HEE} is a dummy for assignment to only health entertainment-education. 
		\textit{HEEC} is a dummy for assignment to health entertainment-education with cash incentives for test performance. 
		Robust standard errors.
		All regressions include dummies for randomization strata, where strata are defined by gender, neighborhood, and microfinance client status.
		***\$\,p < 0.01$, **\$\,p < 0.05$, *\$\,p<0.10$.
		}
		\end{table}) ;

exit ;

